<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@include file="/common/session.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <title>修改密码</title>
    <link rel="stylesheet" href="${ctx}/css/default.css"/>
    <link rel="stylesheet" href="${ctx}/css/xtable.css"/>
    <script type="text/javascript" src="${ctx}/js/qrcode.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/UserService.js"></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form id="accountForm" name="accountForm" onsubmit="return updateAccountPassword();">
    <input type="hidden" id="accountId" name="accountId" value="${accountId}"/>
    <table width="99%" cellspacing="5" cellpadding="5" class="xTbody">
        <tr>
            <td>
                <input type="number" id="accountPassword0" name="accountPassword0" placeholder="原密码" required/>
            </td>
        </tr>
        <tr>
            <td>
                <input type="number" id="accountPassword1" name="accountPassword1" placeholder="新设密码" required/>
            </td>
        </tr>
        <tr>
            <td>
                <input type="number" id="accountPassword2" name="accountPassword2" placeholder="确认密码" required/>
            </td>
        </tr>
        <tr>
            <td align="center">
                <button type="submit" style="width: 100%">修改密码</button>
            </td>
        </tr>
        <tr>
            <td align="center">
                <div id="qrcode" style="display: none;"></div>
                <div id="wxcode"></div>
                <br>用户推荐二维码
            </td>
        </tr>
    </table>
</form>
</body>
</html>
<script type="text/javascript">
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        text: "https://www.dazongpai.com/am/user/register.jsp?managerUserId=${userId}",
        width: 200,
        height: 200,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.Q,
        img_src: "${ctx}/images/logo-mini.png",
        img_width: 50
    });
    //从 canvas 提取图片 image
    function convertCanvasToImage(canvas) {
        var image = new Image();
        image.src = canvas.toDataURL("image/png");
        return image;
    }
    var img = convertCanvasToImage(document.getElementsByTagName("canvas")[0]);
    $("wxcode").append(img); //imagQrDiv表示你要插入的容器id
    function updateAccountPassword() {
        if (!dwr.util.getValue("accountId")) {
            showMessage("用户ID为空");
            return false;
        }
        if (dwr.util.getValue("accountPassword1") != dwr.util.getValue("accountPassword2")) {
            showMessage("确认密码不一致");
            return false;
        }

        var account = new Account();
        account.accountId = "${accountId}";
        account.accountPassword = dwr.util.getValue("accountPassword1");

        var accountOldPassword = dwr.util.getValue("accountPassword0");
        UserService.updateAccountPassword(account, accountOldPassword, function (flag) {
            if (flag == 1) {
                loading("密码修改成功，请重新登录");
//                parent.window.document.getElementById("logoutLi").click ();
            } else {
                loading("原密码错误");
            }
        });
        return false;
    }
</script>
